﻿using System;
using OneMG.Phoenix.Entity;
using OneMG.Phoenix.Respository;
using IBatisNet.DataMapper;
using OneMG.Phoenix.Kernel.IBatisUtil;
using System.Collections;
using System.Collections.Generic;

namespace OneMG.Phoenix.IBatisRepository
{
    public class LinksRepository : BaseIBatisDao,ILinks
    {
        public LinksRepository()
            : base("yihaoke_newMap.Config")
        {

        }
        public System.Int32 AddLinks(ELinks entity)
        {
			string stmtId = "LinksMap.InsertLinks";
			 Object obj = base.SqlMapper.Insert(stmtId, entity);
			 return (System.Int32)obj;
        }
        
		public  ELinks GetByLinkID (System.Int32 linkID)
        {
			string stmtId = "LinksMap.SelectByLinkID";
			return base.SqlMapper.QueryForObject<ELinks>(stmtId, linkID);
        }
        
        public  void DeleteByLinkID (System.Int32 linkID)
        {
			string stmtId = "LinksMap.DeleteByLinkID";
			base.SqlMapper.Update(stmtId, linkID);
        }
        
        public  void UpdateByLinkID (ELinks entity)
        {
			string stmtId = "LinksMap.UpdateByLinkID";
			base.SqlMapper.Update(stmtId, entity);
        }

        public IList<ELinks> GetPagedList(int pageSize, int pageIndex, out int totalRecord)
        {
            totalRecord = base.SqlMapper.QueryForObject<int>("LinksMap.SelectAllRecord", null);

            if (pageIndex > totalRecord)
                pageIndex = 1;

            int startPage = pageSize * pageIndex - pageSize;

            int endPage = pageSize * pageIndex;

            Hashtable ht = new Hashtable();
            ht.Add("StartPage", startPage);
            ht.Add("EndPage", endPage);

            string stmtId = "LinksMap.SelectAllPagedList";

            return base.SqlMapper.QueryForList<ELinks>(stmtId, ht);


        }


    }
}

